﻿using UnityEngine;
using System.Collections;

namespace UI
{
    public class UIHeroSkillIcon : MonoBehaviour
    {
        public UISkill skill;

        public TextureKit skillIcon;

        public UILabel skillType;
        public UILabel skillName;
        public UILabel skillGetPower;
        public UILabel skillDes;
        public UILabel skillLevel;
        public UILabel skillGot;
        public UISprite propIcon;
        public UILabel propType;

        public void Init(UISkill skill,int level,int index)
        {
            this.skill = skill;
            this.skillName.text = TableTextBlo.GetText("name_skill_" + skill.skillData.SkillId);
            skillIcon.textureName = skill.skillData.SkillIcon;
            SetSkillType(Dict.Blo.DictSkillCastBlo.GetSkillExportType(skill.skillData.SkillId));
            skillIcon.texture.depth = 20;
            if (index < 2)
            {
                this.skillType.text = TableTextBlo.GetText(string.Format("normal_skill_{0:d}", index + 1));
                skillLevel.gameObject.SetActive(false);
                skillGot.text = TableTextBlo.GetText("got_power");
                string str = string.Format("{0}", (int)Dict.Blo.DictSkillCastBlo.GetSkillAddAnger(skill.skillData.SkillId));
                skillGetPower.text = str;
                this.skillDes.text = TableTextBlo.GetText("desc_skill_" + skill.skillData.SkillId);
            }
            else
            {

                var coolDown = Dict.Blo.DictConfigBlo.GetSkillCoolDown();

                skillLevel.gameObject.SetActive(true);
                skillLevel.text = TableTextBlo.GetText("level")+level;
                skillType.text = "[" + TableTextBlo.GetText("unique_skill") + "]";
                skillGot.text = TableTextBlo.GetText("cooldown_time");
                skillGetPower.text = coolDown+TableTextBlo.GetText("round");

                float value = skill.skillData.LevelGrowFactor * (level - 1) + (float)Dict.Blo.DictSkillCastBlo.GetSkillExportFactor(skill.skillData.SkillId);

                string str = string.Format("{0}", value);

                string descstr = string.Format(TableTextBlo.GetText("desc_skill_" + skill.skillData.SkillId), str);
                this.skillDes.text = descstr;
            }
    
        }

        void SetSkillType(int type)
        {
            switch (type)
            {
                case 1:
                    propIcon.spriteName = "UI_item_01";
                    propType.text = TableTextBlo.GetText("skill_type_physics");
                    break;
                case 2:
                    propIcon.spriteName = "UI_item_02a";
                    propType.text = TableTextBlo.GetText("skill_type_magic");
                    break;
                case 3:
                    propIcon.spriteName = "UI_item_02";
                    propType.text = TableTextBlo.GetText("skill_type_cure");
                    break;
                default:
                    Debug.LogError("Type error: " + type);
                    break;
            }
        }
    }
}